﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using ScriptEditor.Commands;
using System.Reflection;

namespace ScriptEditor
{
    public enum TYPE
    {
        STRING,
        FLOAT,
        INT,
        BOOL
    }
    public enum PATH
    {
        Linear,
        CatmullRom,
        CubicBezier
    }
    public struct ChoiceExp
    {
        public string text;
        public string jumpId;
        public string exp;
        public override string ToString()
        {
            return text + "^" + jumpId + ((exp == "") ? "" : "@" + exp);
        }
        public static ChoiceExp toChoiceExp(string choice)
        {
            ChoiceExp result;
            if (choice == "")
            {
                result.jumpId = "";
                result.exp = "";
                result.text = "";
                return result;
            }
            result.text = choice.Substring(0, choice.IndexOf('^'));
            if (choice.Contains("@"))
            {
                result.jumpId = choice.Substring(choice.IndexOf('^') + 1, choice.IndexOf('@') - choice.IndexOf('^') - 1);
                result.exp = choice.Substring(choice.IndexOf('@') + 1);
            }
            else
            {
                result.jumpId = choice.Substring(choice.IndexOf('^') + 1);
                result.exp = null;
            }
            return result;
        }
    }
    public struct Vector2
    {
        public float x;
        public float y;
    }
    public struct Vector3
    {
        public float x;
        public float y;
        public float z;
    }
    public struct Color
    {
        public byte r;
        public byte g;
        public byte b;
    }
    public enum Ease
    {
        Unset,
        Linear,
        InSine,
        OutSine,
        InOutSine,
        InQuad,
        OutQuad,
        InOutQuad,
        InCubic,
        OutCubic,
        InOutCubic,
        InQuart,
        OutQuart,
        InOutQuart,
        InQuint,
        OutQuint,
        InOutQuint,
        InExpo,
        OutExpo,
        InOutExpo,
        InCirc,
        OutCirc,
        InOutCirc,
        InElastic,
        OutElastic,
        InOutElastic,
        InBack,
        OutBack,
        InOutBack,
        InBounce,
        OutBounce,
        InOutBounce,
        Flash,
        InFlash,
        OutFlash,
        InOutFlash,
        INTERNAL_Zero,
        INTERNAL_Custom
    }
    public enum Loop
    {
        Restart,    //重新开始，后面的动画循环播放会从起点重新开始
        Yoyo,   //来回播放
        Incremental //增加的，后面的path移动动画会在上一次循环的终点的基础上进行播放
    }
    public enum Rotate
    {
        Fast,
        FastBeyond360,
        WorldAxisAdd,
        LocalAxisAdd
    }
    public enum PathMode
    {
        Ignore,
        Full3D,
        TopDown2D,
        Sidescroller2D
    }
    public enum TextAlignmentOptions
    {
        TopLeft = 257,
        Top,
        TopRight = 260,
        TopJustified = 264,
        TopFlush = 272,
        TopGeoAligned = 288,
        Left = 513,
        Center,
        Right = 516,
        Justified = 520,
        Flush = 528,
        CenterGeoAligned = 544,
        BottomLeft = 1025,
        Bottom,
        BottomRight = 1028,
        BottomJustified = 1032,
        BottomFlush = 1040,
        BottomGeoAligned = 1056,
        BaselineLeft = 2049,
        Baseline,
        BaselineRight = 2052,
        BaselineJustified = 2056,
        BaselineFlush = 2064,
        BaselineGeoAligned = 2080,
        MidlineLeft = 4097,
        Midline,
        MidlineRight = 4100,
        MidlineJustified = 4104,
        MidlineFlush = 4112,
        MidlineGeoAligned = 4128,
        CaplineLeft = 8193,
        Capline,
        CaplineRight = 8196,
        CaplineJustified = 8200,
        CaplineFlush = 8208,
        CaplineGeoAligned = 8224
    }
    public enum GameState
    {
        Splash,
        Title,
        Vn,
        Loading,
        Hacking,
        Message,
        CharacterDev,
        Hacking2,
        Hacking3,
        Hacking4,
        Setting,
        SaveLoad,
        GalleryCG,
        GalleryMusic,
        GalleryVoice,
        Hacking5,
        StaffNormal,
        StaffEnding,
        Copyright,
        PV
    }
    public class Script : ObservableCollection<Command>
    {
        List<CommandUI> pool = new List<CommandUI>();
        public Dictionary<string,CommandUI> GetCommandUIAt(int index,out Command command)
        {
            command = this[index];
            Dictionary<string, CommandUI> result = new Dictionary<string, CommandUI>();
            PropertyInfo[] infos = command.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
            int i = 0;
            foreach (PropertyInfo info in infos)
            {
                if (i >= pool.Count)
                {
                    pool.Add(new CommandUI());
                }
                pool[i].CommandUIInit(info.Name, CommandUI.Type2UIType(info.PropertyType), info.GetValue(this[index], null));
                result.Add(info.Name, pool[i]);
                i++;
            }
            return result;
        }
    }
}
